package com.guidinggame.adapter;

import java.util.List;
import java.util.Map;

import com.example.guidinggame.R;

import android.R.integer;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class MoreListAdapter extends BaseAdapter {

	private Context context;
	private LayoutInflater mInflater;
	private List<Map<String, Object>> mData;
	
	
	public MoreListAdapter(Context context,List<Map<String, Object>> mData) {
		super();
		this.context=context;
		this.mData=mData;
		this.mInflater=LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mData.size();
	}

	

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int position, View conventView, ViewGroup parent) {
		ItemViewHolder holder = null;
		//final int p=position;
        if (conventView == null) {
            holder=new ItemViewHolder();  
            conventView = mInflater.inflate(R.layout.more_item, null);
            holder.icon = (ImageView)conventView.findViewById(R.id.icon_morelist_item);
            holder.itemText = (TextView)conventView.findViewById(R.id.title_morelist_item);
            holder.info = (TextView)conventView.findViewById(R.id.info_morelist_item);
            holder.tipBtn = (Button)conventView.findViewById(R.id.btn_morelist_item);
            conventView.setTag(holder);
             
        }else {
             holder = (ItemViewHolder)conventView.getTag();
        }
         
         
        holder.icon.setBackgroundResource((Integer)mData.get(position).get("img"));
        holder.itemText.setText((String)mData.get(position).get("title"));
        holder.info.setText((String)mData.get(position).get("info"));
        final ItemViewHolder tempHolder=holder;
        holder.tipBtn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
            	//showToast("holder:"+tempHolder.itemText.getText().toString());
            }
        });
        return conventView;
	}
	
	public void showToast(String text){
		Toast.makeText(this.context, text, Toast.LENGTH_SHORT).show();
	}

	public final class ItemViewHolder{
		TextView info;
		ImageView icon;
		TextView itemText;
		Button tipBtn;
		//Map<String, String> otherInfo;
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}
}
